<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统参数列表</title>
<link href="${ctx }/css/ztreeStyle.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/css/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/css/ajax_tip.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/js/layui/css/layui.css" rel="stylesheet" type="text/css" />
<style type="text/css">
    .formtitle{
        height: 29px;
        margin-bottom: 8px;
    }
    .listBtnDiv{
        margin-top: -8px;
        margin-right: 0px;
    }
    .leftTreeDiv{
        width: 220px;
        float: left;
        margin: 10px;
        padding: 10px;
        margin-top: 0px;
        margin-right: 0px;
        padding-top:3px;
    }
    .zTreeDemoBackground{
        width: 210px;
        height: 100%;
        overflow: auto;
    }
    #pageList{
        top: -16px;
        left:-9px;
    }
    .rightinfo{
        padding-top:14px;
    }
</style>
</head>
<body>
<div class="listNavTitle">
    <p>
        <label>系统管理 ></label>
        <label>系统参数管理</label>
    </p>
</div>
<div class="rightinfo">
    <div class="formtitle">
        <span id="parentSpanName">当前选择行政区域:未选择</span>
        <div class="listBtnDiv">
            <@shiro.hasPermission name="sysman:systemParam_man:type_view">
                <button id="paramType" class="layui-btn layui-btn-normal" title="button">参数类型</button>
            </@shiro.hasPermission>
            <@shiro.hasPermission name="sysman:systemParam_man:add">
                <button id="add" class="layui-btn layui-btn-normal" title="button">新增系统参数</button>
            </@shiro.hasPermission>
        </div>
    </div>
    <div class="leftTreeDiv">
        <table class="tablelist">
            <thead>
            <tr>
                <th>行政区域</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>
                    <div class="zTreeDemoBackground left">
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
  <form id="searchForm">
      <input type="hidden" name="areaId" value="0" id="areaId"/>
	  <ul class="search_forminfo">
          <li>
              <label>参数类别</label>
              <select name="typeId">
                  <option value="">请选择</option>
              <#list systemParamTypeList as systemParamType>
                  <option value="${systemParamType.id}">${systemParamType.name}</option>
              </#list>
              </select>
          </li>
          <li>
              <label>字典类型</label>
              <select name="dicTypeId" id="dicTypesel" onchange="dicList();">
                  <option value="">请选择</option>
              <#list systemDicTypeList as dicType>
                  <option value="${dicType.id}">${dicType.name}(${dicType.typeCode})</option>
              </#list>
              </select>
          </li>
          <li>
              <label>字典数据</label>
              <select name="dicId" id="dicIdsel">
                  <option value=>请选择</option>
              </select>
          </li>
	    <!-- 查询条件 -->
	    <li style="">
	      <label>&nbsp;</label>
          <button class="layui-btn layui-btn-normal" type="button" onclick="baseSearchQueryLayer('1','20')">查询</button>
	    </li>
	  </ul>
  </form>
  <div id="pageList" style="float:left;margin-left:10px;clear: none;">
  	
  </div>
</div>
</body>
</html>
<script type="text/javascript" src="${ctx}/js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="${ctx}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctx}/js/common.js"></script>
<script type="text/javascript" src="${ctx }/js/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${ctx }/js/layui/layui.js"></script>
<script type="text/javascript">
$(document).ready(function(){

	initUrl('${ctx}/sysman/systemParam/systemParamAjaxList.do','','${ctx}/sysman/systemParam/toChangeView.do','${ctx}/sysman/systemParam/delSystemParam.do');

    baseSearchQueryLayer(1,20);

	$("#add").click(function(){
	    var areaId = $("#areaId").val();
        toBaseLayer(false,933,530,true,'${ctx}/sysman/systemParam/toSystemParamAdd.do?areaId='+areaId);
	});

    $("#paramType").click(function(){
        toBaseLayer(false,933,530,true,'${ctx}/sysman/systemParamType/systemParamTypeList.do');
    });

    $(".zTreeDemoBackground").height($(window).height()-210);
    $("#pageList").width($(window).width()-300);
    $(".rightinfo").height($(window).height()-80);
    onloadNav();
});

function dicList(){
    var dicTypeId = $("#dicTypesel option:selected").val();
    if(panIsNull(dicTypeId)){
        return;
    }
    $("#dicIdsel").html('<option value>请选择</option>');
    var loadi = layer.load();
    $.ajax({
        type : "POST",
        url : '${ctx}/sysman/systemDic/innList.do',
        data : {"dicTypeId":dicTypeId},
        dataType : "json",
        success : function(data) {
            layer.close(loadi);
            var options = '<option value>请选择</option>';
            for(var i = 0;i<data.length;i++){
                options = options + "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
            }
            $("#dicIdsel").html(options);
        }
    });
}

var selAreaId;
var systemAreaList = ${systemAreaList};
// 加载权限资源图数据
function onloadNav(){
    var loadi = layer.load();
    var setting = {
        data: {
            simpleData: {
                enable: true
            }
        },
        async: {
            enable: true,
            url:"${ctx}/sysman/systemArea/innerList.do",
            autoParam:["id=parentId"],
            dataFilter: filter
        },
        callback: {
            onClick: onClick

        }
    };
    if(panIsNull(systemAreaList)){
        layer.alert('机关行政区域未找到数据');
        return;
    }
    var jsondata="[";
    for(var i = 0;i<systemAreaList.length;i++){
        jsondata+="{'pId':'"+systemAreaList[i].parentid+"','id':'"+systemAreaList[i].id+"','name':'"+systemAreaList[i].areaname+"'},"
    }
    jsondata = jsondata.substring(0,jsondata.length-1);
    jsondata+="]";
    jsondata=eval(jsondata);
    $.fn.zTree.init($("#treeDemo"), setting, jsondata);
    layer.close(loadi);
}

function filter(treeId, parentNode, childNodes) {
    if (!childNodes){ return null;}
    var jsondata="[";
    for(var i = 0;i<childNodes.length;i++){
        jsondata+="{'pId':'"+childNodes[i].parentid+"','id':'"+childNodes[i].id+"','name':'"+childNodes[i].areaname+"','levels':'"+childNodes[i].level+"','id':'"+childNodes[i].id+"','type':'area'},"
    }
    jsondata = jsondata.substring(0,jsondata.length-1);
    jsondata+="]";
    jsondata=eval(jsondata);
    return jsondata;
}
var area = '';
function refreshNodes(treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
    if(area.indexOf(treeNode.id)<0) {
        area += "," + treeNode.id;
        treeNode.isParent = true;
        zTree.reAsyncChildNodes(treeNode, 'refresh', false);
    }
}

function onClick(event, treeId, treeNode, clickFlag) {
    selAreaId=treeNode.id;
    $("#areaId").val(selAreaId);
    refreshNodes(treeNode);
    baseSearchQueryLayer(1,'Refresh');
    $("#parentSpanName").html('当前选择行政区域:'+treeNode.name);
}
</script>